#! /usr/bin/python3
import shelve, pyperclip, sys

# Saves and loads pieces of text to the clipboard.
# Usage: mcb.pyw save <keyword> - Saves clipboard to keyword
#       mcb.pyw <keyword> - Loads keyword to clipboard
#       mcb.pyw list - Loads all keywords to clipboard

mcbShelf = shelve.open("mcb")
# 保存剪贴板内容
if len(sys.argv) == 3 and sys.argv[1].lower() == "save":
    mcbShelf[sys.argv[2]] = pyperclip.paste()
elif len(sys.argv) == 2:
    # 列出所有的Key值
    if sys.argv[1].lower() == "list":
        pyperclip.copy(str(list(mcbShelf.keys())))
    # 通过Key值装载对应的内容到剪贴板
    elif sys.argv[1] in mcbShelf:
        pyperclip.copy(mcbShelf[sys.argv[1]])
mcbShelf.close()
